import path from 'path'
/**
 * 筛选出可供筛选的路由对象
 * @param {*} routes 路由表
 * @param {*} basePath 基础路径
 * @param {*} perfixTitle title数组
 */
export const generateRoutes = (routes, basePath = '/', perfixTitle = []) => {
  let list = []
  for (const route of routes) {
    const data = {
      path: path.resolve(basePath, route.path),
      title: [...perfixTitle]
    }

    // 当前存在 meta时，使用i18n进行国际化解析，组合成新的 title
    // 动态路由不允许被检索
    // 正则
    const reg = /.*\/:.*/
    if (route.meta && route.meta.title && !reg.test(route.path)) {
      // const i18nTitle = i18n.global.t(`msg.route.${route.meta.title}`)
      // data.title = [...data.title, i18nTitle]
      data.title = [...data.title, route.meta.title]
      list.push(data)
    }
    if (route.children) {
      const tempList = generateRoutes(route.children, data.path, data.title)
      list = [...list, ...tempList]
    }
  }
  return list
}
